/**
 *
 * @author Ryan Thomas <s548169@sbuniv.edu>
 * @version 0.7
 */
package MultiUserChatServer;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class MultiUserChatServer {

    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) {
        DebugHandler debug = new DebugHandler();
        try {
            ThreadLinkedList threads = new ThreadLinkedList();
            Controller controlNode = new Controller();
            ServerSocket welcomeSocket = new ServerSocket(65530);
            ServerInputMonitorThread background = new ServerInputMonitorThread(controlNode, threads, debug);
            background.start();
            while(controlNode.get()){
                Socket connectionSocket = welcomeSocket.accept();
                if(controlNode.get()){
                    if(debug.get()){
                        System.out.println("New User Connected @:" + connectionSocket.getInetAddress().getHostAddress());
                    }
                    ClientThread newClient = new ClientThread(connectionSocket, threads, debug);
                    threads.addThread(newClient);
                    newClient.start();
                }
            }
        } catch (IOException ex) {
            if(debug.get()){
                System.out.println(ex.getMessage());
            }
        } 
    }
}
